function openEditChartParamWindow(title) {
    var data
    if (Ext.getCmp('chartParamGrid').getSelection().length > 0 && title != "增加图表参数") {
        data = Ext.getCmp('chartParamGrid').getSelection()[0].data
    }
    console.log(data)
    var chartParamEditWindow = Ext.create('Ext.window.Window', {
        title: title,
        iconCls: 'x-fa fa-database',
        width: 350,
        modal: true,
        items: [{
            xtype: 'form',
            width: '100%',
            height: '100%',
            border: false,
            items: [{
                    xtype: 'hiddenfield',
                    id: 'paramId',
                    value: data == null ? "" : data.param_id
                },
                {
                    xtype: 'textfield',
                    id: 'paramName',
                    labelAlign: 'right',
                    allowBlank: false,
                    fieldLabel: '参数名称',
                    value: data == null ? "" : data.param_name
                },
                {
                    xtype: 'combobox',
                    labelAlign: 'right',
                    id: 'paramType',
                    editable: false,
                    allowBlank: false,
                    valueField: 'id',
                    displayField: 'text',
                    store: Ext.create('Ext.data.Store', {
                        data: [{
                                "id": "string",
                                "text": "字符串"
                            },
                            {
                                "id": "number",
                                "text": "数值"
                            }
                        ]
                    }),
                    fieldLabel: '参数类型',
                    value: data == null ? "string" : data.param_type
                },
                {
                    xtype: 'textfield',
                    id: 'paramDefault',
                    labelAlign: 'right',
                    allowBlank: false,
                    fieldLabel: '参数默认值',
                    value: data == null ? "" : data.param_default
                }
            ],
            buttons: [{
                    xtype: 'button',
                    text: '取消',
                    handler: function () {
                        chartParamEditWindow.close()
                    }
                },
                {
                    xtype: 'button',
                    text: '确定',
                    handler: function () {

                        var paramName = Ext.getCmp("paramName").getValue()
                        var paramType = Ext.getCmp("paramType").getValue()
                        var paramDefault = Ext.getCmp("paramDefault").getValue()
                        var paramId = Ext.getCmp("paramId").getValue()

                        Ext.Ajax.request({
                            url: "../chartparam/save",
                            params: {
                                paramId: paramId,
                                paramName: paramName,
                                paramType: paramType,
                                paramDefault: paramDefault,
                                chartId: chartId
                            },
                            success: function (response, opts) {
                                chartParamEditWindow.close()
                                chartParamStore.getProxy().extraParams.id = chartId
                                chartParamStore.load()
                            }
                        })


                    }
                }
            ]
        }]
    })
    chartParamEditWindow.show()
}

var chartParamStore = Ext.create('Ext.data.Store', {
    autoLoad: true,
    pageSize: 111,
    remoteSort: true,
    remoteFilter: true,
    listeners: {
        beforeload: function () {},
        load: function (obj, records, successful, operation, eOpts) {
            chartParam = []
            for (var i = 0; i < records.length; i++) {
                chartParam.push(records[i].data)
            }
        }
    },
    proxy: {
        type: 'ajax',
        url: '../chartparam/store',
        reader: {
            type: 'json',
            root: 'results',
            totalProperty: 'total'
        }
    }
});
var chartInfoWindow = Ext.create('Ext.window.Window', {
    title: '图表属性',
    iconCls: 'x-fa fa-table',
    height: 500,
    width: 800,
    //layout: 'fit',
    modal: true,
    closeAction: 'hide',
    items: [{
        xtype: 'tabpanel',
        width: '100%',
        height: 500,
        defaults: {
            bodyPadding: 10,
            scrollable: true
        },
        items: [{
                title: '基本信息',
                items: [

                    {
                        xtype: 'container',
                        layout: 'vbox',
                        width: '100%',
                        items: [{
                                layout: 'column',
                                width: '100%',
                                defaults: {
                                    layout: 'form',
                                    xtype: 'container',
                                    tyle: 'width: 50%;'
                                },
                                items: [{
                                        items: [{
                                                xtype: 'displayfield',
                                                id: 'propertyFileName',
                                                fieldLabel: '图表名称',
                                                value: ''
                                            },
                                            {
                                                xtype: 'displayfield',
                                                id: 'propertyToken',
                                                fieldLabel: '链接(Token)',
                                                value: ''
                                            }
                                        ]
                                    },
                                    {
                                        items: [{
                                                xtype: 'displayfield',
                                                fieldLabel: '创建日期',
                                                id: 'propertyCreateDate',
                                                value: ''
                                            },
                                            {
                                                xtype: 'displayfield',
                                                fieldLabel: '修改日期',
                                                id: 'propertyUpdateDate',
                                                value: ''
                                            }
                                        ]
                                    }

                                ]

                            },
                            {
                                xtype: 'container',
                                layout: 'vbox',
                                width: 700,
                                height: 300,
                                items: [{
                                        xtype: 'checkboxfield',
                                        fieldLabel: '行模式',
                                        id:'rowMode',
                                        listeners: {
                                            change: function (obj, newValue, oldValue, eOpts) {
                                                if (newValue!=rowMode) {
                                                    if (newValue==true) {
                                                        //dataSourceDataset = Ext.clone(chartSource.dataset)
                                                        eval("var myOption = "+chartSourceDis)
                                                        var tobj = myOption
                                                        tobj.dataset = rowToColumn(chartSource.dataset)
                                                        chartSourceDis = formatSource(tobj)
                                                        chartSource.dataset = rowToColumn(chartSource.dataset)
                                                    } else {
                                                        chartSource.dataset = Ext.clone(dataSourceDataset)
                                                        eval("var myOption = "+chartSourceDis)
                                                        var tobj = myOption
                                                        tobj.dataset = Ext.clone(dataSourceDataset)
                                                        chartSourceDis = formatSource(tobj)
                                                        console.log(chartSourceDis)
                                                    }
                                                    $('#sourceContent2').html(formatSource(chartSource))
                                                    refreshPreview()
                                                } 
                                                rowMode = newValue
                                                //console.log(rowToColumn(datasetBackup))
                                               
                                            }
                                        }
                                    },
                                    {
                                        xtype: 'checkboxfield',
                                        fieldLabel: '动态图表实例',
                                        id:'dynamicSeries',
                                        listeners: {
                                            change: function (obj, newValue, oldValue, eOpts) {
                                                window.dynamicSeries = newValue
                                            }
                                        }
                                    },
                                    {
                                        xtype: 'checkboxfield',
                                        fieldLabel: '显示为表格',
                                        id:'displayTable',
                                        listeners: {
                                            change: function (obj, newValue, oldValue, eOpts) {
                                                console.log(newValue)
                                                displayTable = newValue
                                                
                                                refreshPreview()

                                            }
                                        }
                                    },
                                    {
                                        xtype: 'numberfield',
                                        //labelAlign:'right'
                                        width: 200,
                                        minValue: 0,
                                        value: 0,
                                        id:'refreshTime',
                                        fieldLabel: '自动刷新时间\r\n(秒)',
                                        listeners: {
                                            change: function (obj, newValue, oldValue, eOpts) {
                                                refreshTime = newValue
                                            }
                                        }
                                    }/*,
                                    {
                                        xtype: 'numberfield',
                                        //labelAlign:'right'
                                        width: 200,
                                        minValue: 0,
                                        value: 0,
                                        id:'yShifting',
                                        fieldLabel: 'Y轴偏移量(%)'
                                    }*/


                                ]
                            }
                            /*,
                            {
                                xtype:'displayfield',
                                labelAlign:'top',
                                width:'100%',
                                height:'100%',
                                htmlEncode:true,
                                value:"<script src='112.73.81.170:8080/app/chart.js'></script>"+
                                "<div chartToken='' style='width:500px;height:500px'></div>",
                                fieldLabel:'Javascript访问代码'
                            }
                            ,
                            {
                                xtype:'displayfield',
                                labelAlign:'top',
                                width:'100%',
                                id:'clientJavascript',
                                height:'100%',
                                htmlEncode:true,
                                value:"<script src='112.73.81.170:8080/app/chart.js'></script>"+
                                "<div chartToken='' style='width:500px;height:500px'></div>",
                                fieldLabel:''
                            }*/


                        ]
                    }



                ]
            },
            {
                title: '图表参数',
                bodyPadding: 0,
                items: [{
                    xtype: 'grid',
                    title: '',
                    id: 'chartParamGrid',
                    store: chartParamStore,
                    width: '100%',
                    height: '100%',
                    tbar: [{
                            xtype: 'button',
                            text: '增加',
                            iconCls: 'x-fa fa-plus',
                            handler: function () {
                                openEditChartParamWindow('增加图表参数')

                            }
                        },
                        {
                            xtype: 'button',
                            text: '修改',
                            iconCls: 'x-fa fa-pencil',
                            handler: function () {
                                openEditChartParamWindow('修改图表参数')

                            }
                        },
                        {
                            xtype: 'button',
                            text: '删除',
                            iconCls: 'x-fa fa-minus',
                            handler: function () {
                                var paramId = Ext.getCmp('chartParamGrid').getSelection()[0].data.param_id
                                Ext.Ajax.request({
                                    url: "../chartparam/delete",
                                    params: {
                                        paramId: paramId
                                    },
                                    success: function (response, opts) {
                                        chartParamStore.reload()
                                    }
                                })

                            }
                        }
                    ],
                    columns: [{
                            text: "参数名",
                            dataIndex: "param_name"
                        },
                        {
                            text: "参数类型",
                            dataIndex: "param_type",
                            renderer: function (value, metaData, record) {
                                if (value == "number") {
                                    return "数值"
                                }
                                if (value == "string") {
                                    return "字符串"
                                }

                            }

                        },
                        {
                            text: "默认值",
                            dataIndex: "param_default"
                        }
                    ]
                }]
            }
        ]
    }]
})